home *** CD-ROM | disk | FTP | other *** search
- package asp.wizard;
-
- import asp.netobjects.nfx.util.ExceptionHandler;
- import asp.netobjects.nfx.util.ExternalError;
- import asp.netobjects.nfx.util.InternalError;
- import asp.netobjects.nfx.wizard.Wizard;
- import asp.netobjects.nfx.wizard.WizardPage;
- import asp.netobjects.nfx.wizard.WizardView;
- import asp.util.EResourceUtil;
- import asp.util.ResourceUtil;
- import asp.wizard.def.DefCollection;
- import asp.wizard.def.DefConnection;
- import asp.wizard.def.DefList;
- import asp.wizard.def.DefPage;
- import asp.wizard.def.DefQuery;
- import asp.wizard.def.LayoutGenerator;
- import asp.wizard.util.UiUtil;
- import com.netobjects.nfc.api.DSiteView;
- import com.sun.java.swing.ImageIcon;
- import com.sun.java.swing.JFrame;
- import java.awt.Component;
- import java.awt.Dialog;
- import java.awt.Font;
- import java.awt.Frame;
- import java.awt.Window;
- import java.awt.event.WindowEvent;
- import java.net.URL;
- import java.util.Enumeration;
- import java.util.Hashtable;
- import java.util.Vector;
-
- public class WizardManager extends Wizard {
- public static final int WIDTH = 540;
- public static final int HEIGHT = 400;
- public static final int TEMPLATE_LIST = 0;
- public static final int TEMPLATE_DETAIL = 1;
- public static final int TEMPLATE_FINISH = 2;
- protected static final int NUM_OF_TEMPLATES = 3;
- private static final String ID_LBL_TITLE = "window.title";
- private static final String IMG_DIR = "image";
- private static final String BUTTON_CANCEL = "button.cancel";
- private static final String BUTTON_BACK = "button.back";
- private static final String BUTTON_NEXT = "button.next";
- private static final String BUTTON_FINISH = "button.finish";
- public static final String TITLE_GENERATE = "window.title.generate";
- private SeqTemplate[] _seqTemplates = new SeqTemplate[3];
- private Vector _models = new Vector();
- private DefPage _firstDefPage;
- private Hashtable _modelDependents = new Hashtable();
- private ResourceUtil _resourceUtil;
- private boolean _modelSkippingEnabled = true;
- private DSiteView _siteView;
- private boolean _finished = false;
- private boolean _closed = false;
-
- public static void main(String[] args) {
- UiUtil.lafSetup();
- JFrame f = createMainFrame();
- WizardManager wm = new WizardManager(f, (String)null, (String)null, 540, 400, new AspWizardExceptionHandler(f));
- Window win = ((Wizard)wm).getView();
- win.addWindowListener(new 1());
- ((Wizard)wm).setVisible(true);
- }
-
- public static JFrame createMainFrame() {
- JFrame result = new JFrame();
- ((Component)result).setFont(new Font("Dialog", 0, 11));
- return result;
- }
-
- public WizardManager(JFrame parent, String title, String codeBase, int width, int height, ExceptionHandler handler) {
- super(parent, title, codeBase, width, height, handler);
- this.init_internal();
- }
-
- public WizardManager(JFrame parent, String title, String codeBase, ExceptionHandler handler) {
- super(parent, title, codeBase, handler);
- this.init_internal();
- }
-
- protected void init_internal() {
- this.initResourceUtil();
- this.initView();
- this.initTemplates();
- this.initSequence();
- ((Wizard)this).enableButtons();
-
- try {
- this.initialize();
- } catch (Exception e) {
- System.err.println(((Throwable)e).getMessage());
- }
-
- }
-
- private void initResourceUtil() {
- try {
- this._resourceUtil = new ResourceUtil("asp.wizard.res", this.getClass());
- } catch (EResourceUtil e) {
- System.err.println(((Throwable)e).getMessage());
- }
-
- }
-
- private void initView() {
- WizardView wv = ((Wizard)this).getView();
- if (wv != null) {
- ((Dialog)wv).setTitle(this._resourceUtil.getString("window.title"));
- URL u = this.getClass().getResource("image/transicon.gif");
- if (u != null) {
- ImageIcon icon = new ImageIcon(u);
- if (wv instanceof Frame) {
- ((Frame)wv).setIconImage(icon.getImage());
- }
- }
-
- wv.getCancelButton().setText(this._resourceUtil.getString("button.cancel"));
- wv.getBackButton().setText(this._resourceUtil.getString("button.back"));
- wv.getNextButton().setText(this._resourceUtil.getString("button.next"));
- wv.getFinishButton().setText(this._resourceUtil.getString("button.finish"));
- UiUtil.centerComponentInScreen(wv);
- ((Dialog)wv).setResizable(false);
- }
-
- ((Window)wv).addWindowListener(new 2(this));
- }
-
- private void handleWindowClosing(WindowEvent e) {
- WizDbManager.releaseInstance();
- this._closed = true;
- }
-
- private void handleWindowClosed(WindowEvent e) {
- WizDbManager.releaseInstance();
- this._closed = true;
- }
-
- private void initTemplates() {
- this._seqTemplates[0] = new SeqTemplateList(this, 0);
- this._seqTemplates[1] = new SeqTemplateDetail(this, 1);
- this._seqTemplates[2] = new SeqTemplateFinish(this, 2);
- }
-
- private void initSequence() {
- try {
- WizardModelAbstract model = new WizardModelIntro(this, (String)null, (String)null, (ImageIcon)null, (ExceptionHandler)null);
- this.add(model);
- model.initialize(1);
- } catch (InternalError e) {
- System.err.println(((Throwable)e).getMessage());
- } catch (ExternalError e) {
- System.err.println(((Throwable)e).getMessage());
- }
-
- }
-
- private boolean isValidTemplateId(int templateId) {
- boolean result = false;
- switch (templateId) {
- case 0:
- case 1:
- case 2:
- result = true;
- break;
- default:
- result = false;
- }
-
- return result;
- }
-
- public void add(WizardPage page) throws InternalError {
- if (page != null) {
- if (!((WizardModelAbstract)page).isRegisteredWithWizard()) {
- super.add(page);
- }
-
- if (this._models.indexOf(page) == -1) {
- this._models.addElement(page);
- }
-
- }
- }
-
- public void addSequence(WizardPage afterNode, WizardPage seqOwner, DefPage assocPage, int nextTemplateId, DefPage parentPage) {
- if (parentPage != null) {
- parentPage.addChildPage(assocPage);
- }
-
- if (this.isValidTemplateId(nextTemplateId)) {
- try {
- WizardPage seqHead = this._seqTemplates[nextTemplateId].addSequence(afterNode, assocPage);
- this._modelDependents.put(seqOwner, seqHead);
- } catch (ESeqTemplate e) {
- System.err.println(((Throwable)e).getMessage());
- }
- }
-
- }
-
- public void removeSequence(WizardPage headNode) {
- if (headNode != null) {
- WizardModelAbstract model = (WizardModelAbstract)headNode;
- if (this.isValidTemplateId(model.getTemplateId())) {
- SeqTemplate seqTemplate = this._seqTemplates[model.getTemplateId()];
- if (seqTemplate.isSeqComplete(model)) {
- int startIndex = this._models.indexOf(headNode);
- int endIndex = startIndex + seqTemplate.getLength() - 1;
- WizardModelAbstract prevModel = (WizardModelAbstract)this.getPreviousModel(model);
- DefPage parentDefPage = prevModel.getDefPage();
- DefPage currDefPage = model.getDefPage();
-
- for(int i = endIndex; i >= startIndex; --i) {
- this.removeModel(i);
- }
-
- if (currDefPage != null) {
- this.removeDefPage(prevModel, model.getTemplateId(), currDefPage);
- }
- }
- }
-
- }
- }
-
- protected void removeModelDependent(WizardPage model) {
- WizardPage dependent = (WizardPage)this._modelDependents.get(model);
- if (dependent != null) {
- this.removeSequence(dependent);
- this._modelDependents.remove(model);
- }
-
- }
-
- protected void removeModel(int index) {
- this.removeModelDependent((WizardPage)this._models.elementAt(index));
- Hashtable hash = ((Wizard)this).getPageIndex();
- if (hash != null) {
- hash.remove(this._models.elementAt(index));
- }
-
- this._models.removeElementAt(index);
- }
-
- public WizardPage getNextModel(WizardPage currModel) {
- WizardPage result = null;
- if (currModel == null) {
- return result;
- } else {
- int curridx = this._models.indexOf(currModel);
- if (curridx < 0) {
- return result;
- } else {
- if (curridx < this._models.size() - 1) {
- result = (WizardPage)this._models.elementAt(curridx + 1);
- }
-
- return result;
- }
- }
- }
-
- public WizardPage getPreviousModel(WizardPage currModel) {
- WizardPage result = null;
- if (currModel == null) {
- return result;
- } else {
- int curridx = this._models.indexOf(currModel);
- if (curridx < 0) {
- return result;
- } else {
- if (curridx > 0 && curridx < this._models.size()) {
- result = (WizardPage)this._models.elementAt(curridx - 1);
- }
-
- return result;
- }
- }
- }
-
- void insertModels(WizardPage afterNode, Vector newseq) {
- int nodeindex = this._models.indexOf(afterNode);
- if (nodeindex >= this._models.size() - 1) {
- Enumeration e = newseq.elements();
-
- while(e.hasMoreElements()) {
- this._models.addElement(e.nextElement());
- }
- } else {
- int i = nodeindex;
- Enumeration e = newseq.elements();
-
- while(e.hasMoreElements()) {
- Vector var10000 = this._models;
- Object var10001 = e.nextElement();
- ++i;
- var10000.insertElementAt(var10001, i);
- }
- }
-
- }
-
- public DefPage getFirstDefPage() {
- return this._firstDefPage;
- }
-
- public void setFirstDefPage(DefPage firstDefPage) {
- this._firstDefPage = firstDefPage;
- }
-
- public String getReport(WizardModelAbstract currPage) {
- String result = null;
- int prevTemplateId = ((WizardModelAbstract)this.getPreviousModel(currPage)).getTemplateId();
- if (prevTemplateId == 1) {
- result = "A detail page containing:\n\t- MSDBQuery1\n\t- MSDBConnection1\n\t- MSDBDetail\nhas been created.";
- } else if (prevTemplateId == 0) {
- result = "A list page containing:\n\t- MSDBQuery1\n\t- MSDBConnection1\n\t- MSDBList\nhas been created.";
- }
-
- return result;
- }
-
- private int getSequenceHeadIndex(WizardPage model) {
- int result = -1;
- WizardModelAbstract wm = (WizardModelAbstract)model;
- int modelIndex = this._models.indexOf(wm);
- if (modelIndex != -1) {
- int tid = wm.getTemplateId();
- int currIndex = modelIndex;
- boolean found = false;
- WizardModelAbstract wmprev = null;
-
- while(!found) {
- wmprev = (WizardModelAbstract)this._models.elementAt(currIndex - 1);
- Class tailClass = this._seqTemplates[tid].getClassOfLastModel();
- found = wmprev.getTemplateId() != tid || tailClass == wmprev.getClass();
- if (!found) {
- --currIndex;
- }
-
- if (currIndex < 0) {
- break;
- }
- }
-
- if (found) {
- result = currIndex;
- }
- }
-
- return result;
- }
-
- public WizardPage getSequenceHead(WizardPage model) {
- WizardPage result = null;
- int headIndex = this.getSequenceHeadIndex(model);
- if (headIndex != -1) {
- result = (WizardPage)this._models.elementAt(headIndex);
- }
-
- return result;
- }
-
- private int getModelIndexOfClassLeftOf(Class modelClass, int headIndex) {
- int result = -1;
- boolean found = false;
-
- for(int i = headIndex; i >= 0 && !found; --i) {
- found = modelClass == this._models.elementAt(i).getClass();
- if (found) {
- result = i;
- }
- }
-
- return result;
- }
-
- private int getModelIndexOfClassRightOf(Class modelClass, int headIndex) {
- int result = -1;
- boolean found = false;
-
- for(int i = headIndex; i != -1 && i < this._models.size() && !found; ++i) {
- found = modelClass == this._models.elementAt(i).getClass();
- if (found) {
- result = i;
- }
- }
-
- return result;
- }
-
- public WizardPage getModelOfClassLeftOf(Class modelClass, WizardPage headModel) {
- WizardPage result = null;
- int headIndex = this._models.indexOf(headModel);
- int foundIndex = this.getModelIndexOfClassLeftOf(modelClass, headIndex);
- if (foundIndex != -1) {
- result = (WizardPage)this._models.elementAt(foundIndex);
- }
-
- return result;
- }
-
- public WizardPage getModelOfClassRightOf(Class modelClass, WizardPage headModel) {
- WizardPage result = null;
- int headIndex = this._models.indexOf(headModel);
- int foundIndex = this.getModelIndexOfClassRightOf(modelClass, headIndex);
- if (foundIndex != -1) {
- result = (WizardPage)this._models.elementAt(foundIndex);
- }
-
- return result;
- }
-
- public WizardPage getModelOfClass(Class modelClass, WizardPage model) {
- WizardPage result = null;
- int headIndex = this.getSequenceHeadIndex(model);
- int modelIndex = this.getModelIndexOfClassRightOf(modelClass, headIndex);
- if (modelIndex != -1) {
- result = (WizardPage)this._models.elementAt(modelIndex);
- }
-
- return result;
- }
-
- public DefConnection getDefConnection(WizardModelAbstract model) {
- DefConnection result = null;
- int tid = model.getTemplateId();
- if (this.isValidTemplateId(tid)) {
- SeqTemplate seqTemplate = this._seqTemplates[tid];
- result = seqTemplate.getDefConnection(model);
- }
-
- return result;
- }
-
- public DefQuery getDefQuery(WizardModelAbstract model) {
- DefQuery result = null;
- int tid = model.getTemplateId();
- if (this.isValidTemplateId(tid)) {
- SeqTemplate seqTemplate = this._seqTemplates[tid];
- result = seqTemplate.getDefQuery(model);
- }
-
- return result;
- }
-
- public DefList getDefList(WizardModelAbstract model) {
- DefList result = null;
- int tid = model.getTemplateId();
- if (this.isValidTemplateId(tid)) {
- SeqTemplate seqTemplate = this._seqTemplates[tid];
- result = seqTemplate.getDefList(model);
- }
-
- return result;
- }
-
- public boolean isModelSkippingEnabled() {
- return this._modelSkippingEnabled;
- }
-
- public void setModelSkippingEnabled(boolean value) {
- this._modelSkippingEnabled = value;
- }
-
- public void setDSiteView(DSiteView sv) {
- this._siteView = sv;
- }
-
- public void finish() throws ExternalError, InternalError {
- this._finished = true;
- }
-
- public boolean isFinished() {
- return this._finished;
- }
-
- public boolean isClosed() {
- return this._closed;
- }
-
- public void processDefPages() {
- if (this._firstDefPage != null && this._siteView != null) {
- try {
- LayoutGenerator gen = new LayoutGenerator(this._siteView);
- gen.addLayoutGeneratorListener(new GenProgressDisplay());
- gen.generate(this._firstDefPage);
- } catch (Exception e) {
- AspWizardExceptionHandler.showMessage(0, ((Throwable)e).getMessage());
- }
- } else if (this._firstDefPage == null) {
- String msg = "finish(): _firstDefPage is null";
- AspWizardExceptionHandler.showMessage(-2, msg);
- } else if (this._siteView == null) {
- String msg = "finish(): _siteView is not specified";
- AspWizardExceptionHandler.showMessage(-2, msg);
- }
-
- }
-
- public void initialize() throws InternalError, ExternalError {
- super.initialize();
- WizardPage model = (WizardPage)((Wizard)this).getPageIndex().get("1");
- if (model != null) {
- model.initialize(1);
- if (!model.getView().isVisible()) {
- model.getView().setVisible(true);
- }
- }
-
- ((Wizard)this).enableButtons();
- }
-
- public DefPage createDefPage(WizardPage currModel, int nextSeqTemplateId) {
- DefPage result = null;
- if (this.isValidTemplateId(nextSeqTemplateId)) {
- result = this._seqTemplates[nextSeqTemplateId].createDefPage();
- }
-
- return result;
- }
-
- private void removeDefPage(WizardPage currModel, int nextSeqTemplateId, DefPage toRemove) {
- if (this.isValidTemplateId(nextSeqTemplateId)) {
- this._seqTemplates[nextSeqTemplateId].reclaimDefPageId();
- ((DefCollection)toRemove).removeAllElements();
- DefPage currPage = ((WizardModelAbstract)currModel).getDefPage();
- if (currPage != null) {
- currPage.removeChildPage(toRemove);
- }
- }
-
- }
-
- public void updateNextDefPageId(WizardPage currModel, int nextSeqTemplateId) {
- if (this.isValidTemplateId(nextSeqTemplateId)) {
- this._seqTemplates[nextSeqTemplateId].updateNextDefPageId();
- }
-
- }
-
- public boolean isUsePreviousQuery(WizardPage model) {
- boolean result = false;
- if (((WizardModelAbstract)model).getTemplateId() == 1) {
- WizardPage headModel = this.getSequenceHead(model);
- WizardPage prevHeadModel = this.getPreviousModel(headModel);
- if (prevHeadModel != null) {
- result = !(prevHeadModel instanceof WizardModelIntro);
- }
- }
-
- return result;
- }
-
- // $FF: synthetic method
- static void access$0(WizardManager $0, WindowEvent $1) {
- $0.handleWindowClosing($1);
- }
-
- // $FF: synthetic method
- static void access$1(WizardManager $0, WindowEvent $1) {
- $0.handleWindowClosed($1);
- }
- }
-